/**
 * Created by huangxiaoming by 20180624
 */
;(function (window, $, jquery) {
    $(function () {
        _YHC_UTIL.scrollTop();
        setTimeout(function () {
            $("#homeTab").css("color", "#d4b36b");
            $(".navbar .container").css("border-bottom", "1px solid #393838")
        }, 100)
        $(".bannerfir").height($(window).height());
        $(window).resize(function () {          //当浏览器大小变化时
            $(".bannerfir").height($(window).height());
        });


        goNews = function () {
            window.location.href = "./news_1.html";
        }


        ////////////////////  ui  ////////////////////
        var CM = {};
        CM.intro = {
            start: function () {
                if ($('#dv_scroll').length) CM.intro.iniScr();
            }
            ,
            iniScr: function () {
                var scroller = null;
                var scrollbar = null;
                scroller = new Scrolling.Scroller(document.getElementById('dv_scroll'), 430, 209);
                scrollbar = new Scrolling.Scrollbar(document.getElementById('dv_scroll_bar'), scroller, new Scrolling.ScrollTween());
            }
        };
        ////////////////////  start  ////////////////////
        setTimeout(function () {
            CM.intro.start();
        }, 500);
        // 以下是地图配置————————————————————————————————————————————————————————————————————————————————————————————————————————//
        var mapoption = {
            tooltip: {
                trigger: 'item',
                formatter: function (datas) {
                    var res = datas.data.name;
                    res += "<span style='color:#fff;font-size:16px;'>&nbsp&nbsp共" + datas.data.value + '所</span>';
                    return res;
                },
                enterable: true,
                borderColor: '#d4b36b',
                borderWidth: 2,
                backgroundColor: "#d4b36b",//提示标签背景颜色
                textStyle: {color: "#000"} //提示标签字体颜色
            },
            visualMap: {
                show: false,
                min: 0,
                max: 100,
                left: 'left',
                top: 'bottom',
                text: ['签约率(%)', ''],           // 文本，默认为数值文本
                calculable: true,
                inRange: {
                    color: ["transparent"]
                }
            },
            toolbox: {
                show: false,
                orient: 'vertical',
                left: 'right',
                top: 'center',
                feature: {
                    mark: {show: true},
                    dataView: {readOnly: false},
                    restore: {},
                    saveAsImage: {}
                }
            },
            series: [
                {
                    name: '法院',
                    type: 'map',
                    mapType: 'china',
                    roam: false,
                    selectedMode: 'single',
                    coordinateSystem: 'geo',// series坐标系类型
                    label: {
                        normal: {
                            show: false,//显示省份标签
                            textStyle: {color: "#fff"}//省份标签字体颜色
                        },
                        emphasis: {//对应的鼠标悬浮效果
                            show: true,
                            textStyle: {color: "#fff"}
                        }
                    },
                    // left:'center',
                    // top:'30px',
                    itemStyle: {//===============图形样式，有 normal 和 emphasis 两个状态。normal 是图形在默认状态下的样式；emphasis 是图形在高亮状态下的样式，比如在鼠标悬浮或者图例联动高亮时。
                        normal: {
                            borderWidth: .5,//区域边框宽度
                            borderColor: '#d4b36b',//区域边框颜色
                            areaColor: "#ebc59a",//区域颜色
                        },
                        emphasis: {
                            borderWidth: .5,
                            borderColor: '#000',
                            areaColor: "#d4b36b"
                        }
                    },
                    data: [
                        {name: '北京', value: 19, yes: 0, no: 0},
                        {name: '天津', value: 17, yes: 0, no: 0},
                        {name: '上海', value: 27, yes: 0, no: 0, selected: true},
                        {name: '重庆', value: 16, yes: 0, no: 0},
                        {name: '河北', value: 26, yes: 0, no: 0},
                        {name: '河南', value: 31, yes: 0, no: 0},
                        {name: '云南', value: 24, yes: 0, no: 0},
                        {name: '辽宁', value: 26, yes: 0, no: 0},
                        {name: '黑龙江', value: 24, yes: 0, no: 0},
                        {name: '湖南', value: 26, yes: 0, no: 0},
                        {name: '安徽', value: 41, yes: 0, no: 0},
                        {name: '山东', value: 47, yes: 0, no: 0},
                        {name: '新疆', value: 24, yes: 0, no: 0},
                        {name: '江苏', value: 65, yes: 0, no: 0},
                        {name: '浙江', value: 61, yes: 0, no: 0},
                        {name: '江西', value: 14, yes: 0, no: 0},
                        {name: '湖北', value: 32, yes: 0, no: 0},
                        {name: '广西', value: 37, yes: 0, no: 0},
                        {name: '甘肃', value: 24, yes: 0, no: 0},
                        {name: '山西', value: 20, yes: 0, no: 0},
                        {name: '内蒙古', value: 23, yes: 0, no: 0},
                        {name: '陕西', value: 38, yes: 0, no: 0},
                        {name: '吉林', value: 19, yes: 0, no: 0},
                        {name: '福建', value: 21, yes: 0, no: 0},
                        {name: '贵州', value: 21, yes: 0, no: 0},
                        {name: '广东', value: 57, yes: 0, no: 0},
                        {name: '青海', value: 5, yes: 0, no: 0},
                        {name: '西藏', value: 2, yes: 0, no: 0},
                        {name: '四川', value: 43, yes: 0, no: 0},
                        {name: '宁夏', value: 6, yes: 0, no: 0},
                        {name: '海南', value: 4, yes: 0, no: 0},
                        {name: '台湾', value: 0, yes: 0, no: 0},
                        {name: '香港', value: 0, yes: 0, no: 0},
                        {name: '澳门', value: 0, yes: 0, no: 0},
                        {name: '南海诸岛', value: 0, yes: 0, no: 0}
                    ]
                }
            ]
        };

        var myChartmap = echarts.init(document.getElementById('map'));
        myChartmap.setOption(mapoption);
        // myChartmap.on("click", function (param) {
        //     console.log(param)
        //     $('#mapProvince').text(param.name);
        //     queryLawfirmInfoList(param.name);
        // });
        $('#map').removeAttr("style");

        var tempAllfirmInfoList = new Array();
        //默认显示上海
//        $scope.mapProvince = "上海";
        // queryLawfirmInfoList("上海");

        //查询律所信息
        function queryLawfirmInfoList(province) {
            var headerInfo = {}, bizInfo = {};
            headerInfo.pageNum = '';
            headerInfo.pageSize = '';
            headerInfo.sessionId = "180703142510EC2OJLH0A0IX9J630533";

            bizInfo.province = province;
            _YHC_UTIL.queryProxyBizData("queryLawfirmInfoList", headerInfo, bizInfo,
                function (tempData) {
                    if(tempData.isSuccess=='T'){
                        console.log("查询合作律所信息成功=",JSON.parse(tempData.body))
                        var tempfirmInfoList = JSON.parse(tempData.body).lawfirmInfoList;
                        tempAllfirmInfoList = tempfirmInfoList;
                        $('#mapFirmList').html('');
                        for(var i=0;i<tempfirmInfoList.length;i++){
                            $('#mapFirmList').append('<li>'+tempfirmInfoList[i].lawfirmName+'</li>')
                        }
                        setTimeout(function () {
                            CM.intro.start();
                        }, 100);
                        if (tempAllfirmInfoList.length > 9) {
                            $('#dv_scroll_bar').show()
                        } else {
                            $('#dv_scroll_bar').hide()
                        }
                        $('#mapCityList').html('<option value="">请选择城市</option>');
                        if (tempAllfirmInfoList.length > 0) {
                            var cityListData = unique(tempAllfirmInfoList);
                            for(var i=0;i<cityListData.length;i++){
                                $('#mapCityList').append('<option value='+cityListData[i].city+'>'+cityListData[i].city+'</option>')
                            }
                        }
                    }
                }, function (data) {
                    console.log("查询合作律所信息失败", data)
                    tempAllfirmInfoList = new Array();
                    // getfirmList($scope.cityData[0].city);
                });
        }
        mapCityChange=function () {
            var val=$('#mapCityList').val()
            console.log(val)
            if(val){
                getfirmList(val)
            }
        }
        //数组去重复
        function unique(target) {
            var result = new Array();
            loop:
                for (var i = 0, n = target.length; i < n; i++) {
                    for (var x = i + 1; x < n; x++) {
                        if (target[x].city === target[i].city)
                            continue loop;
                    }
                    result.push(target[i]);
                }
            return result;
        }

        //根据城市名获取列表
        function getfirmList(cityName) {
           var tempList = new Array();
           if(tempAllfirmInfoList.length>0){
               for(var i=0;i<tempAllfirmInfoList.length;i++){
                   if(tempAllfirmInfoList[i].city == cityName){
                       tempList.push(tempAllfirmInfoList[i]);
                   }
               }
           }
            $('#mapFirmList').html('');
            for(var i=0;i<tempList.length;i++){
                $('#mapFirmList').append('<li>'+tempList[i].lawfirmName+'</li>')
            }
           if(tempList.length > 9){
               $('#dv_scroll_bar').show()
           } else {
               $('#dv_scroll_bar').hide()
           }
        }

// 地图配置结束————————————————————————————————————————————————————————————————————————————————————————————————————————//

        // queryDdVersionList();

        //获取数据字典
        function queryDdVersionList(){
            var serviceName = "queryDdVersionList";
            var headerInfo = {},bizInfo = {};
            headerInfo.pageNum =  '';
            headerInfo.pageSize = '';
            headerInfo.sessionId = "";
            $.ajax({
                url:'/biz.ajax',
                method:'get',
                cache:false,
                headers: {
                    "Accept" : "text/plain; charset=utf-8",
                    "Content-Type": "text/plain; charset=utf-8"
                },
                data:{
                    'serviceName': serviceName,
                    'headerInfo': JSON.stringify(headerInfo),
                    'bizInfo': JSON.stringify(bizInfo)
                },
                success:function(data,textStatus,jqXHR){
                    var returnData = JSON.parse(data);
                    if(returnData.isSuccess == "T"){
                        var tempDBdata = JSON.parse(returnData.body);
                        //判断数据字典
                        var tempDdVersionString = localStorage.getItem("dfzxDdVersionList");
                        if(!tempDdVersionString){
                            //存储数据字典数据
                            localStorage.setItem("dfzxDdVersionList", JSON.stringify(tempDBdata.ddVersionList));
                            queryCaseTypeList();
                        }else{
                            if(tempDdVersionString != JSON.stringify(tempDBdata.ddVersionList)){
                                queryCaseTypeList();
                            }
                        }
                    }
                },
                error:function(xhr,textStatus){
                    console.log('失败=',xhr)
                }
            })
        }

        //获取案件类型数据
        function queryCaseTypeList(){
            var serviceName = "queryCaseTypeList";
            var headerInfo = {},bizInfo = {};
            headerInfo.pageNum =  '';
            headerInfo.pageSize = '';
            headerInfo.sessionId = "";
            $.ajax({
                url:'/biz.ajax',
                method:'get',
                cache:false,
                headers: {
                    "Accept" : "text/plain; charset=utf-8",
                    "Content-Type": "text/plain; charset=utf-8"
                },
                data:{
                    'serviceName': serviceName,
                    'headerInfo': JSON.stringify(headerInfo),
                    'bizInfo': JSON.stringify(bizInfo)
                },
                success:function(data,textStatus,jqXHR){
                    var returnData = JSON.parse(data);
                    if(returnData.isSuccess == "T"){
                        var tempCaseTypeList = JSON.parse(returnData.body).caseTypeList;
                        //存储案件类型数据
                        localStorage.setItem("caseTypeListCache", JSON.stringify(tempCaseTypeList));
                        queryCaseStageList();
                    }
                },
                error:function(xhr,textStatus){
                    console.log('失败=',xhr)
                }
            })
        }

        //查询案件阶段信息
        function queryCaseStageList(){
            var serviceName = "queryCaseStageList";
            var headerInfo = {},bizInfo = {};
            headerInfo.pageNum =  '';
            headerInfo.pageSize = '';
            headerInfo.sessionId = "";
            $.ajax({
                url:'/biz.ajax',
                method:'get',
                cache:false,
                headers: {
                    "Accept" : "text/plain; charset=utf-8",
                    "Content-Type": "text/plain; charset=utf-8"
                },
                data:{
                    'serviceName': serviceName,
                    'headerInfo': JSON.stringify(headerInfo),
                    'bizInfo': JSON.stringify(bizInfo)
                },
                success:function(data,textStatus,jqXHR){
                    var returnData = JSON.parse(data);
                    if(returnData.isSuccess == "T"){
                        var tempCaseStageList = JSON.parse(returnData.body).caseStageList;
                        //存储查询案件信息
                        localStorage.setItem("caseStageListCache", JSON.stringify(tempCaseStageList));
                        queryFundUseList();
                    }
                },
                error:function(xhr,textStatus){
                    console.log('失败=',xhr)
                }
            })
        }

        //查询资金用途信息
        function queryFundUseList(){
            var serviceName = "queryFundUseList";
            var headerInfo = {},bizInfo = {};
            headerInfo.pageNum =  '';
            headerInfo.pageSize = '';
            headerInfo.sessionId = "";
            $.ajax({
                url:'/biz.ajax',
                method:'get',
                cache:false,
                headers: {
                    "Accept" : "text/plain; charset=utf-8",
                    "Content-Type": "text/plain; charset=utf-8"
                },
                data:{
                    'serviceName': serviceName,
                    'headerInfo': JSON.stringify(headerInfo),
                    'bizInfo': JSON.stringify(bizInfo)
                },
                success:function(data,textStatus,jqXHR){
                    var returnData = JSON.parse(data);
                    if(returnData.isSuccess == "T"){
                        var tempFundUseList = JSON.parse(returnData.body).fundUseList;
                        //存储查询案件信息
                        localStorage.setItem("fundUseListCache", JSON.stringify(tempFundUseList));
                        queryDocKindList();
                    }
                },
                error:function(xhr,textStatus){
                    console.log('失败=',xhr)
                }
            })
        }

        //查询资料类别信息
        function queryDocKindList(){
            var serviceName = "queryDocKindList";
            var headerInfo = {},bizInfo = {};
            headerInfo.pageNum =  '';
            headerInfo.pageSize = '';
            headerInfo.sessionId = "";
            $.ajax({
                url:'/biz.ajax',
                method:'get',
                cache:false,
                headers: {
                    "Accept" : "text/plain; charset=utf-8",
                    "Content-Type": "text/plain; charset=utf-8"
                },
                data:{
                    'serviceName': serviceName,
                    'headerInfo': JSON.stringify(headerInfo),
                    'bizInfo': JSON.stringify(bizInfo)
                },
                success:function(data,textStatus,jqXHR){
                    var returnData = JSON.parse(data);
                    if(returnData.isSuccess == "T"){
                        var tempDocKindList = JSON.parse(returnData.body).docKindList;
                        localStorage.setItem("docKindListCache", JSON.stringify(tempDocKindList));
                        queryAdvField();
                    }
                },
                error:function(xhr,textStatus){
                    console.log('失败=',xhr)
                }
            })
        }

        //查询擅长领域
        function queryAdvField(){
            var serviceName = "queryAdvFieldList";
            var headerInfo = {},bizInfo = {};
            headerInfo.pageNum =  '';
            headerInfo.pageSize = '';
            headerInfo.sessionId = "";
            $.ajax({
                url:'/biz.ajax',
                method:'get',
                cache:false,
                headers: {
                    "Accept" : "text/plain; charset=utf-8",
                    "Content-Type": "text/plain; charset=utf-8"
                },
                data:{
                    'serviceName': serviceName,
                    'headerInfo': JSON.stringify(headerInfo),
                    'bizInfo': JSON.stringify(bizInfo)
                },
                success:function(data,textStatus,jqXHR){
                    var returnData = JSON.parse(data);
                    if(returnData.isSuccess == "T"){
                        // console.log("查询擅长领域信息=",returnData.body)
                        var tempAdvFieldList = JSON.parse(returnData.body).advFieldList;
                        localStorage.setItem("advFieldListCache", JSON.stringify(tempAdvFieldList));
                    }else{

                    }
                },
                error:function(xhr,textStatus){
                    console.log('失败=',xhr)
                }
            })
        }

        //成功
        // var oDiv=document.getElementById('autoScroll01');
        // var oUl=document.querySelector(".clearfix");
        // var offsetWidth = $(".clearfix li")[0].offsetWidth;
        // var speed=-2;
        // oUl.innerHTML+=oUl.innerHTML;
        // var leg = $(".clearfix li").length;
        // oUl.style.width=offsetWidth*leg+'px';
        // alert(oUl.style.width)
        // function marqueeFn(){
        //     // console.log("oUl.offsetLeft=",oUl.offsetLeft)
        //
        //     if(oUl.offsetLeft<-oUl.offsetWidth/2){
        //         oUl.style.left=0;
        //     }
        //     // if(oUl.offsetLeft>0){
        //     //     oUl.style.left=-oUl.offsetWidth/2+'px';
        //     // }
        //     oUl.style.left=oUl.offsetLeft+speed+'px';
        // }
        // var timer=setInterval(marqueeFn,30);
        // oDiv.onmouseover=function(){
        //     clearInterval(timer);
        // };
        // oDiv.onmouseout=function(){
        //     timer=setInterval(marqueeFn,30);
        // };
        // function opacity(t) {
        //     var time = t*Math.random();
        //     console.log(time);
        //     $('.clearfix li').css('opacity',time);
        // }
        // setTimeout(opacity(1),1000);

    })

})(window, $, jQuery)


